package com.maoguo.config.shiro;

import com.maoguo.user.model.User;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;

import java.util.HashSet;
import java.util.Set;

public class MyShiroRealm extends AuthorizingRealm {
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
        SimpleAuthorizationInfo simpleAuthorizationInfo=new SimpleAuthorizationInfo();
        Set<String> set=new HashSet<String>();
        //set.add("/user111");
        set.add("/login");
        simpleAuthorizationInfo.setStringPermissions(set);
        System.out.println("0------");
        return simpleAuthorizationInfo;
    }

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        String password= (String) token.getPrincipal();
        //password=MD5Util.MD5(password);
        String userName=  new String((char[])token.getCredentials());
        System.out.println("userName==="+userName+"----password===="+password);
        User user=new User();
        user.setName(userName);
        return new SimpleAuthenticationInfo(password,userName,getName());
    }
}
